Python `if x is not None` or `if not x is None`?
Posted
by orokusaki
on Stack Overflow
See other posts from Stack Overflow
or by orokusaki
Published on 2010-04-26T03:10:30Z
Indexed on
2010/04/26
3:13 UTC
Read the original article
Hit count: 183
python
|boolean-expression
I've always thought of the if not x is None
version to be more clear, but Google's style guide implies (based on this excerpt) that they use if x is not None
. Is there any minor performance difference (I'm assuming not), and is there any case where one really doesn't fit (making the other a clear winner for my convention)?*
*I'm referring to any singleton, rather than just None
.
...to compare singletons like None. Use is or is not.
© Stack Overflow or respective owner